package com.eat.controller.admin;

import com.eat.result.Result;
import com.eat.utils.AliOssUtil;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;


@RestController
@RequestMapping("/admin/common")
@Api(tags = "文件上传接口")
public class CommonController {

    @Autowired
    private AliOssUtil aliOssUtil;

    @PostMapping("/upload")
    public Result<String> upload(MultipartFile file) {
//        String originalFilename = file.getOriginalFilename();
//        String upload = null;
//        try {
//            String substring = originalFilename.substring(originalFilename.lastIndexOf('.'));
//            String s = UUID.randomUUID().toString()+substring;
//            upload = aliOssUtil.upload(file.getBytes(), s);
//            return Result.success(upload);
//        } catch (IOException e) {
//            e.printStackTrace();
//        }

        return Result.success("https://sky-itcast.oss-cn-beijing.aliyuncs.com/c09a0ee8-9d19-428d-81b9-746221824113.png");
    }

}
